package org.alternativedev.wo42.gui.menu;

import org.alternativedev.wo42.Game;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.gui.MouseOverArea;

public abstract class MenuOption {
	GameContainer container;
	Image upButton, downButton;
	int x, y;
	MouseOverArea mouseScan;

	public MenuOption(GameContainer container, Image upButton, Image downButton) {
		this.container = container;
		this.upButton = upButton;
		this.downButton = downButton;
		mouseScan = new MouseOverArea(container, upButton, x, y);
	}

	public abstract void onClick(Game game, GameContainer gContainer) throws SlickException;

	public void updateDraw(Graphics g, Game game,GameContainer gContainer) throws SlickException {
		mouseScan.setX(this.getX());
		mouseScan.setY(this.getY());
		upButton.draw(x, y);
		if (mouseScan.isMouseOver()) {
			downButton.draw(x, y);
		}
		if (mouseScan.isMouseOver()
				&& container.getInput().isMouseButtonDown(
						Input.MOUSE_LEFT_BUTTON)) {
			onClick(game, gContainer);
		}
	}

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	public int getWidth() {
		return this.upButton.getWidth();
	}

	public int getHeight() {
		return this.upButton.getHeight();
	}
}
